<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8"/>
    <!--标识百度适应pc和mobile-->
    <meta name="applicable-device" content="pc,mobile">
    <!--禁止百度转码-->
    <meta http-equiv="Cache-Control" content="no-transform"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--启用360浏览器的极速模式-->
    <meta name="renderer" content="webkit"/>
    <!-- 强制Chromium内核，作用于其他双核浏览器 -->
    <meta name="force-rendering" content="webkit"/>
    <!--优先使用 IE 最新版本和 Chrome-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <!--避免IE使用兼容模式-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <!--针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓-->
    <meta name="HandheldFriendly" content="true"/>
    <!--搜索引擎蜘蛛-->
    <meta name="Baiduspider" content="index,follow,noarchive"/>
    <meta name="robots" content="index,follow"/>
    <!--作者及版权-->
    <meta name="author" content="Janecraft"/>
    <meta name="copyright" content="Janecraft"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"/>
    <title>Title</title>
    <meta name="keywords" content="关键词"/>
    <meta name="description" content="描述"/>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">

    <link href="/bootstraptable/bootstrap-table.min.css" rel="stylesheet">
    <style>
        .text_bottom_border{
            border: none;
            border-bottom: 1px solid black;
        }

        .text_no_border{
            border: none;
        }
    </style>
</head>
<body>
<div class="container">
    <div style="width: 1200px;margin: 0 auto;">
        <h5 style="color: #3e79b6">您正在做的业务是：您正在做的业务是：库存管理--出入库调度管理-制定入库单</h5>
    </div>

    <div class="panel panel-default">
        <form id="module_form" class="form-horizontal">
            <div class="panel-heading" style="text-align: right">
                <button type="button" id="submit_btn" class="btn btn-info">提交</button>
                <button type="button" id="fanhui_btn" class="btn btn-info">返回</button>
            </div>
            <div class="panel-body">

                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">入库单编号：</label>
                        <div class="col-sm-8">
                            <label name="gatherId" id="gatherId"
                                   class="form-control text_no_border"
                                   value=""></label>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">产品编号：</label>
                        <div class="col-sm-8">
                            <label name="productId" id="productId"
                                   class="form-control text_bottom_border"
                                   value=""></label>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">产品名称：</label>
                        <div class="col-sm-8">
                            <label name="productName" id="productName"
                                   class="form-control text_no_border"
                                   value=""></label>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">成本单价：</label>
                        <div class="col-sm-8">
                            <label name="costPrice" id="costPrice"
                                   class="form-control text_no_border"
                                   value=""></label>
                        </div>
                    </div>
                </div>
                <!--工序明细表格-->
                <table id="module_details_table" >

                </table>

                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">登记人：</label>
                        <div class="col-sm-8">
                            <label  name="register" id="register"
                                    class="form-control text_bottom_border"
                                    value=""></label>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">登记时间：</label>
                        <div class="col-sm-8">
                            <label readonly="readonly" type="text" name="registerTime" id="registerTime" class="form-control"
                                   value=""></label>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">应入库数：</label>
                        <div class="col-sm-8">
                            <label  name="amount" id="amount"
                                    class="form-control text_bottom_border"
                                    value=""></label>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">已入库数：</label>
                        <div class="col-sm-8">
                            <label readonly="readonly" type="text" name="beInAmount" id="beInAmount" class="form-control"
                                   value=""></label>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">应入库成本：</label>
                        <div class="col-sm-8">
                            <label class="form-control" id="subTotal" name="subTotal"></label>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">已入库成本：</label>
                        <div class="col-sm-8">
                            <label class="form-control" id="beInSubTotal" name="beInSubTotal"></label>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>


</div>

<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/js/plugins/layer/layer.min.js"></script>

<!-- 自定义js -->
<script src="/js/hAdmin.js?v=4.1.0"></script>
<!--<script type="text/javascript" src="/js/index.js"></script>-->

<!-- 第三方插件 -->
<script src="/js/plugins/pace/pace.min.js"></script>

<!--BootstrapTable-->
<script src="/bootstraptable/bootstrap-table.min.js"></script>
<script src="/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>
<script>
    $(function (){
        // 根据入库明细表中的序号查询对应的入库明细表
        let id=localStorage.getItem("id")

        $.get("/storageGather/details/storageGatherDetailsGetId",{"id":id},function (data){
            //     // 设置产品名称和产品编号的回显
            $("#module_form #productId").html(data.productId)
            $("#module_form #productName").html(data.productName)
            $("#module_form #costPrice").html(data.costPrice)
            //应入库数量
            let amount= $("#module_form #amount").html()

            $("#module_form #amount").html(data.amount)
            $("#module_form #subTotal").html(data.subtotal)

            //入库明细的父级序号
            let parentId=data.parentId;
            //入库明细的产品编号
            let productId=data.productId;
            //通过父级id查询入库表的一列
            $.get("/design/storageGather/listGatherById",{"parentId":parentId},function (data){
                //     // 设置产品名称和产品编号的回显
                $("#module_form #gatherId").html(data.gatherId)
                $("#module_form #register").html(data.register)
                $("#module_form #registerTime").html(data.registerTime)

                let parentId=data.parentId;
            })

            //通过产品编号查询出库存单元的数据
            $("#module_details_table").bootstrapTable({
                // 请求方式
                method: "post",
                // 内容类型：如果请求方式是post，内容类型必须是application/x-www-form-urlencoded
                contentType: "application/x-www-form-urlencoded",
                // 请求路径
                url: '/design/storage/ListByProductId',
                // 数据行交替样式
                striped: true,
                // 是否是服务器端分页：server表示服务器端，client表示前端分页
                sidePagination: 'server',
                //初始化加载第一页
                pageNumber: 1,
                //是否分页
                pagination:true,
                // 单页记录数，页大小
                pageSize: 1,
                // 分页列表
                pageList: [1, 2, 3, 4],
                //刷新按钮
                // showRefresh:true,
                // 请求参数
                queryParams: function (params) {
                    let obj = {
                        productId:productId,
                        pageSize: params.limit,
                        pageNo: (params.offset / params.limit) + 1,
                    }
                    return obj;
                },
                // 表格列标题
                columns: [{
                    title: "序号",
                    field: "id",
                    sortable:true
                },{
                    title: "当前可存放数量",
                    field: "amount",
                    formatter:function (value,row,index){
                        let amount=row.maxCapacityAmount-row.amount
                        return amount
                    }
                },{
                    title: "本次入库数量",
                    field: "",
                    formatter:function (value,row,index){
                        let gatheredAmount=`<input type="text"  name="gatheredAmount" class='form-control'>`
                        return gatheredAmount
                    }
                }]
            })
        })


        $("#submit_btn").click(function (){
            // 设置一个空的已入库数量
            let inAmount=0
            //本次入库数量<=最大存储量—当前存储量  本次入库数量=应入库数
            let cellData=$("#module_details_table").bootstrapTable("getData")
            //MAX_CAPACITY_AMOUNT最大存储量
            let maxCapacityAmount=cellData[0].maxCapacityAmount
            //AMOUNT当前存储量
            let amount=cellData[0].amount
            //本次入库数量
            let gatheredAmount=$("#module_details_table input[name='gatheredAmount']").val()
            //应入库数量
            let yAmount= $("#module_form #amount").html()

            //本次入库数量=应入库数
            if(gatheredAmount!=yAmount || gatheredAmount>maxCapacityAmount-amount){
                alert("入库数量有误")
            }else{
                //a)当前存储量=当前存储量+本次入库数量
                inAmount=amount+parseInt(gatheredAmount)
                //当前存储量=已入库数量
                cellData[0].amount=inAmount
                let costPrice=$("#module_form #costPrice").html()
                let subTota=gatheredAmount * parseInt(costPrice)
                //已入库数量
                let beInAmount=$("#module_form #beInAmount").html(gatheredAmount)
                //已入库成本
                let beInSubtotal= $("#module_form #beInSubTotal").html(subTota)
                // 获取页面对应的库存单元
                let cell_one = cellData[0]
                let gather_dto = {"id": localStorage.getItem("id")}
                gather_dto.gatheredAmount=parseInt(gatheredAmount)
                gather_dto.gatherId = $("#module_form #gatherId").html()
                gather_dto.storageCell = cell_one

                //修改该条库存单元的当前存储的
                $.ajax({
                    url: "/storageGather/details/update",
                    type: "post",
                    data: JSON.stringify(gather_dto),
                    contentType: "application/json",
                    success: function (data) {
                        if(data=='correct'){
                            window.location="/storage/storage_gather_in_recheckUI"
                        }
                    }
                })
            }
        })
    })

    $("#fanhui_btn").click(function (){
        window.location="/storage/storage_gather_in_recheckUI"
    })
</script>
</body>
</html>
